/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-03
 * Time: 8:37
 */

class Solution {
    public String replaceSpace(String s) {
        int cnt =0;
        for(int i =0;i<s.length();++i){
            if(s.charAt(i)==' '){
                cnt++;
            }
        }
        char[] ch = new char[s.length()+2*cnt];
        int oldP = s.length()-1;
        int newP = ch.length-1;
        while(oldP<newP){
            char c = s.charAt(oldP);
            if(c==' '){
                ch[newP--] = '%';
                ch[newP--] = '2';
                ch[newP] = '0';
                oldP--;
                newP--;
            }else {
                ch[newP] = s.charAt(oldP);
                newP--;
                oldP--;
            }
        }
        return new String(ch);
    }
}

public class TestDemo {

    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.replaceSpace("We are h");
        String s = "ghjk";
        s.toCharArray();
        Thread.currentThread().isInterrupted();
    }


}
